package com.jml.juc.lock.base;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.AbstractOwnableSynchronizer;
import java.util.concurrent.locks.Condition;

public abstract class AbstractQueuedSynchronizerDemo
        extends AbstractOwnableSynchronizer
        implements java.io.Serializable {

    private static final long serialVersionUID = 7373984972572414691L;
    protected AbstractQueuedSynchronizerDemo() { }
    private transient volatile  Node head;
    private transient volatile  Node tail;
    private volatile int state;
    protected final int getState() {
        return state;
    }
    protected final void setState(int newState) {
        state = newState;
    }
    protected final boolean compareAndSetState(int expect, int update) {
        return Boolean.FALSE;
    }
    static final long spinForTimeoutThreshold = 1000L;
    private  Node enq(final  Node node) {
        return null;
    }
    private  Node addWaiter( Node mode) {
        return null;
    }
    private void setHead( Node node) {
        head = node;
        node.thread = null;
        node.prev = null;
    }
    private void unparkSuccessor( Node node)  {
    }
    private void doReleaseShared() {
    }
    private void setHeadAndPropagate( Node node, int propagate) {
    }
    private void cancelAcquire( Node node) {
    }
    private static boolean shouldParkAfterFailedAcquire( Node pred,  Node node) {
        return Boolean.FALSE;
    }
    static void selfInterrupt() {
    }
    private final boolean parkAndCheckInterrupt() {
        return Boolean.FALSE;
    }
    final boolean acquireQueued(final  Node node, int arg) {
        return Boolean.FALSE;
    }
    private void doAcquireInterruptibly(int arg) throws InterruptedException {
    }
    private boolean doAcquireNanos(int arg, long nanosTimeout) throws InterruptedException {
        return Boolean.FALSE;
    }
    private void doAcquireShared(int arg) {
    }
    private void doAcquireSharedInterruptibly(int arg) throws InterruptedException {
    }
    private boolean doAcquireSharedNanos(int arg, long nanosTimeout) throws InterruptedException {
        return Boolean.FALSE;
    }
    protected boolean tryAcquire(int arg) {
        return Boolean.FALSE;
    }
    protected boolean tryRelease(int arg) {
        return Boolean.FALSE;
    }
    protected int tryAcquireShared(int arg) {
        return 1;
    }
    protected boolean tryReleaseShared(int arg) {
        throw new UnsupportedOperationException();
    }
    protected boolean isHeldExclusively() {
        throw new UnsupportedOperationException();
    }
    public final void acquire(int arg) {

    }
    public final void acquireInterruptibly(int arg) throws InterruptedException {
    }
    public final boolean tryAcquireNanos(int arg, long nanosTimeout) throws InterruptedException {
        return Boolean.FALSE;
    }
    public final boolean release(int arg) {
        tryRelease(arg);
        return Boolean.FALSE;
    }
    public final void acquireShared(int arg) {
    }
    public final void acquireSharedInterruptibly(int arg) throws InterruptedException {
    }
    public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout) throws InterruptedException {
        return Boolean.FALSE;
    }
    public final boolean releaseShared(int arg) {
        return false;
    }
    public final boolean hasQueuedThreads() {
        return head != tail;
    }
    public final boolean hasContended() {
        return head != null;
    }
    public final Thread getFirstQueuedThread() {
        // handle only fast path, else relay
        return (head == tail) ? null : fullGetFirstQueuedThread();
    }
    private Thread fullGetFirstQueuedThread() {
        return new Thread();
    }
    public final boolean isQueued(Thread thread) {
        return false;
    }
    final boolean apparentlyFirstQueuedIsExclusive() {
        return false;
    }
    public final boolean hasQueuedPredecessors() {
        return false;
    }
    public final int getQueueLength() {
        return 1;
    }


    public final Collection<Thread> getQueuedThreads() {
        return new ArrayList<>();
    }
    public final Collection<Thread> getExclusiveQueuedThreads() {
        return new ArrayList<>();
    }
    public final Collection<Thread> getSharedQueuedThreads() {
        return new ArrayList<>();
    }
    @Override
    public String toString() {
        int s = getState();
        String q  = hasQueuedThreads() ? "non" : "";
        return super.toString() +
                "[State = " + s + ", " + q + "empty queue]";
    }
    final boolean isOnSyncQueue( Node node) {
        return findNodeFromTail(node);
    }
    private boolean findNodeFromTail( Node node) {
         return false;
    }
    final boolean transferForSignal( Node node) {
        return true;
    }
    final boolean transferAfterCancelledWait( Node node) {
        return false;
    }
    final int fullyRelease( Node node) {
        release(1);
        return 1;
    }
    public final boolean owns( ConditionObject condition) {
        return false;
    }
    public final boolean hasWaiters( ConditionObject condition) {
        return false;
    }
    public final int getWaitQueueLength( ConditionObject condition) {
        return 1;
    }
    public final Collection<Thread> getWaitingThreads( ConditionObject condition) {
        return new ArrayList<>();
    }

    private static final long stateOffset=1L;
    private static final long headOffset=1L;
    private static final long tailOffset=1L;
    private static final long waitStatusOffset=1L;
    private static final long nextOffset=1L;
    private final boolean compareAndSetHead( Node update) {
        return false;
    }
    private final boolean compareAndSetTail( Node expect,  Node update) {
        return false;
    }
    private static final boolean compareAndSetWaitStatus( Node node,
                                                         int expect,
                                                         int update) {
        return false;
    }
    private static final boolean compareAndSetNext( Node node,
                                                    Node expect,
                                                    Node update) {
        return false;
    }


    static final class Node {
        static final Node SHARED = new Node();
        static final  Node EXCLUSIVE = null;
        static final int CANCELLED =  1;
        static final int SIGNAL    = -1;
        static final int CONDITION = -2;
        static final int PROPAGATE = -3;
        volatile int waitStatus;
        volatile  Node prev;
        volatile  Node next;
        volatile Thread thread;
        Node nextWaiter;
        final boolean isShared() {
            return nextWaiter == SHARED;
        }
        final  Node predecessor() throws NullPointerException {
            return null;
        }
        Node() {
        }
        Node(Thread thread,  Node mode) {
        }

        Node(Thread thread, int waitStatus) {
        }
    }
    public class ConditionObject implements Condition, java.io.Serializable {
        private static final long serialVersionUID = 1173984872572414699L;
        private transient  Node firstWaiter;
        private transient  Node lastWaiter;
        public ConditionObject() { }
        private  Node addConditionWaiter() {
            return null;
        }
        private void doSignal( Node first) {
        }
        private void doSignalAll( Node first) {
        }
        private void unlinkCancelledWaiters() {
        }
        @Override
        public final void signal() {
        }
        @Override
        public final void signalAll() {
        }
        @Override
        public final void awaitUninterruptibly() {
        }
        private static final int REINTERRUPT =  1;
        private static final int THROW_IE    = -1;
        private int checkInterruptWhileWaiting( Node node) {
            return 1;
        }
        private void reportInterruptAfterWait(int interruptMode) throws InterruptedException {
        }
        @Override
        public final void await() throws InterruptedException {
            fullyRelease(null);
        }
        @Override
        public final long awaitNanos(long nanosTimeout) throws InterruptedException {
            return 1L;
        }
        @Override
        public final boolean awaitUntil(Date deadline) throws InterruptedException {
            return true;
        }
        @Override
        public final boolean await(long time, TimeUnit unit) throws InterruptedException {
            return false;
        }
        final boolean isOwnedBy(AbstractQueuedSynchronizerDemo sync) {
            return    false;
        }
        protected final boolean hasWaiters() {
            return false;
        }
        protected final int getWaitQueueLength() {
            return 1;
        }
        protected final Collection<Thread> getWaitingThreads() {
            return null;
        }
    }
}

